<?php

/**
 * This is the model class for table "job_title".
 *
 * The followings are the available columns in table 'job_title':
 * @property integer $ID
 * @property integer $JOB_TITLE_PARENT
 * @property string $JOB_TITLE_NAME
 * @property string $DESCRIPTION
 * @property string $JOB_SUMMARY
 * @property string $MAJOR_DUTY_AND_RESP
 * @property string $CONTEXT
 * @property integer $USER_CREATED
 * @property string $TIME_UPDATED
 * @property integer $USER_UPDATEDS
 * @property string $TIME_UPDATED
 *
 * The followings are the available model relations:
 * @property Employee[] $employees
 * @property JobTitle $jOBTITLEPARENT
 * @property JobTitle[] $jobTitles
 */
class JobTitle extends CMasterModel {

    /**
     * Returns the static model of the specified AR class.
     * @return JobTitle the static model class
     */
    public static function model($className=__CLASS__) {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return 'job_title';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('JOB_TITLE_PARENT, USER_CREATED, USER_UPDATED', 'numerical', 'integerOnly' => true),
            array('JOB_TITLE_NAME', 'length', 'max' => 100),
            array('JOB_TITLE_NAME', 'required'),
            array('DESCRIPTION', 'length', 'max' => 500),
            array('JOB_SUMMARY, MAJOR_DUTY_AND_RESP, CONTEXT', 'length', 'max' => 1000),
            array('TIME_UPDATED, TIME_UPDATED', 'safe'),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('ID, JOB_TITLE_PARENT, JOB_TITLE_NAME, DESCRIPTION, JOB_SUMMARY, MAJOR_DUTY_AND_RESP, CONTEXT, USER_CREATED, TIME_UPDATED, USER_UPDATED, TIME_UPDATED', 'safe', 'on' => 'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'employees' => array(self::HAS_MANY, 'Employee', 'JOB_TITLE_ID'),
            'jOBTITLEPARENT' => array(self::BELONGS_TO, 'JobTitle', 'JOB_TITLE_PARENT'),
            'jobTitles' => array(self::HAS_MANY, 'JobTitle', 'JOB_TITLE_PARENT'),
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
            'ID' => 'ID',
            'JOB_TITLE_PARENT' => 'Parent',
            'JOB_TITLE_NAME' => 'Job Title Name',
            'DESCRIPTION' => 'Description',
            'JOB_SUMMARY' => 'Job Summary',
            'MAJOR_DUTY_AND_RESP' => 'Major Duty And Responsibility',
            'CONTEXT' => 'Context',
            'USER_CREATED' => 'User Created',
            'TIME_UPDATED' => 'Date Created',
            'USER_UPDATED' => 'User Updated',
            'TIME_UPDATED' => 'Date Updated',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search() {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('ID', $this->ID);
        $criteria->compare('JOB_TITLE_PARENT', $this->JOB_TITLE_PARENT);
        $criteria->compare('JOB_TITLE_NAME', $this->JOB_TITLE_NAME, true);
        $criteria->compare('DESCRIPTION', $this->DESCRIPTION, true);
        $criteria->compare('JOB_SUMMARY', $this->JOB_SUMMARY, true);
        $criteria->compare('MAJOR_DUTY_AND_RESP', $this->MAJOR_DUTY_AND_RESP, true);
        $criteria->compare('CONTEXT', $this->CONTEXT, true);
        $criteria->compare('USER_CREATED', $this->USER_CREATED);
        $criteria->compare('TIME_UPDATED', $this->TIME_UPDATED, true);
        $criteria->compare('USER_UPDATED', $this->USER_UPDATED);
        $criteria->compare('TIME_UPDATED', $this->TIME_UPDATED, true);

        return new CActiveDataProvider($this, array(
            'criteria' => $criteria,
        ));
    }

    public function getJobTitleNameID() {
        //dkmprm,dkmnama
        return $this->JOB_TITLE_NAME . '(' . $this->ID . ')';
    }

}